$(function () {
  init();
})
// 初始化
function init(){
    var id = getParam("id");
    // 确定
    var ajax = new $ax("/meeting/queryID", function (data) {
        // 成功
        if (data.status == "true") {
           // window.location.reload();
            var meeting = data.meeting;
            $("#title").val(meeting.title);
            $("#conferenceTime").val(formatDateTimeYMDHM(meeting.conferenceTime));
            $("#meetingPlace").val(meeting.meetingPlace);
            $("#host").val(meeting.host);
            $("#convener").val(meeting.convener);
            $("#conferenceContent").val(meeting.conferenceContent);


            var files = data.fileList;
            for(var i=0; i<files.length; i++){
                var temp = i+1;
                $("#fileID"+temp).val(files[i].id);
                $("#showfile"+temp).html(files[i].noticeFileName);
                $("#showfile"+temp).attr("href", "/yd/meeting/"+files[i].noticeFileName);
            }



        } else {
            // mui.alert(data.message);
            alert("查看失败");
        }

    }, function (data) {
        // 失败
        alert("访问失败");
        errorAjax();
        alert("查看失败");
    });

    ajax.setToken(cookie.get("token"));
    ajax.set("id", id);
    ajax.start();
}

function submit21(){
    var type = "file";          //后台接收时需要的参数名称，自定义即可
    var id = "cert";            //即input的id，用来寻找值
    var formData = new FormData();

    var title = $("#title").val();
    if(title == ""){
        alert("标题不能为空");
        return ;
    }
    var conferenceTime = $("#conferenceTime").val();
    if(conferenceTime == ""){
        alert("会议时间不能为空");
        return ;
    }
    var meetingPlace = $("#meetingPlace").val();
    if(meetingPlace == ""){
        alert("会议地点不能为空");
        return ;
    }
    var host = $("#host").val();
    if(host == ""){
        alert("主持人不能为空");
        return ;
    }
    var convener = $("#convener").val();
    if(convener == ""){
        alert("召集者不能为空");
        return ;
    }
    var conferenceContent = $("#conferenceContent").val();
    if(conferenceContent == ""){
        alert("会议内容不能为空");
        return ;
    }

    var id = getParam("id");
    formData.append("id",id);

    formData.append("title",title);
    formData.append("conferenceTime",conferenceTime);
    formData.append("meetingPlace",meetingPlace);
    formData.append("host",host);
    formData.append("convener",convener);
    formData.append("conferenceContent",conferenceContent);
    formData.append("file1", $("#file1")[0].files[0]);    //生成一对表单属性
    formData.append("file2", $("#file2")[0].files[0]);    //生成一对表单属性
    formData.append("fileID1",$("#fileID1").val());
    formData.append("fileID2",$("#fileID2").val());
    $.ajax({
        type: "POST",           //因为是传输文件，所以必须是post
        url: 'http://localhost:8080/yd/meeting/updageAddFile',         //对应的后台处理类的地址
        data: formData,
        processData: false,
        contentType: false,
        headers:
        {
            "token": cookie.get("token")
        },
        success: function (data) {
            if(data.message == "无token，请重新登录" || data.message == "凭证过期,请重新登录" ){
                errorAjax();
            }else if (data.status == "true") {
                alert("更新成功")
                window.location.href='meeting.html'
            }else {
                alert("更新失败")
            }
        }
    });
}

/**
 * 获取指定的URL参数值
 * URL:http://www.xxxxxxx.com/index?name=tyler
 * 参数：paramName URL参数
 * 调用方法:getParam("name")
 * 返回值:tyler
 */
function getParam(paramName) {
    paramValue = "", isFound = !1;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
        arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
        while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
    }
    return paramValue == "" && (paramValue = null), paramValue
}


//return y + '-' + m + '-' + d +' '+h+':'+minute;
function formatDateTimeYMDHM(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    return y + '-' + m + '-' + d +' '+h+':'+minute;
};